<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
    <title>Virus Bacteria Interaction Prediction</title>
    <link rel="stylesheet" type="text/css" href="lib/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="lib/css/jquery-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="lib/jqwidgets/styles/jqx.base.css" />
    <link rel="stylesheet" type="text/css" href="css/styles.css"/>
    <link rel="stylesheet" type="text/css" href="lib/css/custom_new.css">
    
    <script type="text/javascript" src="lib/js/d3.js"></script>
    <script type="text/javascript" src="lib/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="lib/js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="lib/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="lib/js/math.min.js"></script>
    <script type="text/javascript" src="lib/jqwidgets/jqx-all.js"></script>
</head>


<body>
	
<div id="tooltip1" class="hidden"><p><span id="value"></div>

<div id="container-id-1" style="width: 1670px; height: 1000px; clear: both;">
	<div class="sidebar_wrapper" style="float: left; width: 300px; height: 1000px; overflow: hidden; display: block; border-right: 1px solid grey;">
		<div class="title_section">
			<img class="title_image" src="logo.jpg" alt="" style="width: 290px; margin-left: 2px; margin-top: 5px;">
		</div>
		
		<div class="reorder_section" style="margin: 1px; margin-top: 10px; padding:2px; font-size: 11px; border: 0.5px solid grey;">
			<div id='jqxWidget'><label>Select the Virus for visualization: </label><div id="listbox"></div></div>
			
			<div class="opacity_slider_container" style="margin-top: 5px;">
				<div ><label for="topAmount"># of top Hosts: </label><input type="text" value="25" id="topAmount" readonly style="border:0; font-weight:bold; width: 50px;"></div>
				<div id="topSlider" style="width: 290px;"></div>
			</div>
			<div class="opacity_slider_container" style="margin-top: 5px;">
				<div ><label for="cutoffAmount">Max distance &lt;= </label><input type="text" value="1" id="cutoffAmount" readonly style="border:0; font-weight:bold; width: 50px;"></div>
				<div id="cutoffSlider" style="width: 290px;"></div>
			</div>
			<div class="btn-group gene_search_button" data-toggle="buttons" style="margin-top: 10px;">
				<div><button id="okBtn" class="sidebar_text btn btn-primary submit_gene_button" type="button" disabled="true" onclick="updateData()" style="float: left; padding-top: 6px; padding-bottom: 6px;">OK</button></div>
			</div>
		</div>
	</div>
	<div id="vizcontainer" style="float: left; width: 1000px; height: 800px; overflow: auto; ">
		<svg id="heatCanvas"></svg> 
	</div>
	<div style="float: left;margin-left: 20px; margin-top: 50px; ">
		<div><b>Consensus Information</b></div>
		<div id="consensusSuperkingdom"></div>
		<div id="consensusPhylum"></div>
		<div id="consensusClass"></div>
		<div id="consensusOrder"></div>
		<div id="consensusFamily"></div>
		<div id="consensusGenus"></div>
		<div id="consensusSpecies"></div>
	</div>
</div>


<footer id="footer_div" class="footer navbar-fixed-bottom">
    <div class="row"><div class="col-xs-12 footer_section"><p class="text-muted">Copyright (C) 2016 Yang Lu &lt;<a href="mailto:ylu465@usc.edu">ylu465@usc.edu</a>&gt; @ Computational and Molecular Biology, Department of Biological Science, University of Southern California, LA, CA 90089, USA </p></div></div>
</footer>

<script type="text/javascript">
	var margin = {top: 200, right: 10, bottom: 10, left: 200};
   var colors = ['#91003F','#9B1A53','#A63467','#B14F7C','#BB6990','#C684A4','#D19EB9','#DBB9CD','#E6D3E1','#F1EEF6','#FFFFFF'];
   
   var virusNameIdxMap = new Object(), hostNameIdxMap = new Object();   
   var topHostNum = 50, cutoff = 1;
   var checkedVirusIdxArr = [], checkedVirusArr = [], hostArr = [], edgeData =[];
   var virusNameArr = ["NC_019843.3.fasta", "NC_004297.0.fasta", "NC_001802.1.fasta", "NC_001722.1.fasta", "NC_002023.0.fasta", "NC_004718.3.fasta", "NC_006998.1.fasta", "AC_000017.1.fasta", "NC_003977.2.fasta", "NC_012532.1.fasta", "NC_045512.2.fasta", "NC_038312.1.fasta", "NC_002728.1.fasta", "NC_006273.2.fasta", "NC_001803.1.fasta", "NC_009333.1.fasta", "NC_001348.1.fasta", "NC_001798.2.fasta", "NC_001538.1.fasta", "NC_001355.1.fasta", "NC_001436.1.fasta", "NC_005219.1.fasta", "NC_001430.1.fasta", "NC_001906.3.fasta", "NC_038311.1.fasta", "NC_010415.1.fasta", "NC_001731.1.fasta", "JX276378.1.fasta", "NC_006307.0.fasta", "NC_001806.2.fasta", "NC_001796.2.fasta", "NC_001611.1.fasta", "NC_003443.1.fasta", "NC_001664.4.fasta", "NC_002549.1.fasta", "NC_004102.1.fasta", "NC_002204.0.fasta", "NC_007605.1.fasta", "NC_004162.2.fasta"];
var hostNameArr = ["NC_019843.3.fasta", "NC_004297.0.fasta", "NC_001802.1.fasta", "NC_001722.1.fasta", "NC_002023.0.fasta", "NC_004718.3.fasta", "NC_006998.1.fasta", "AC_000017.1.fasta", "NC_003977.2.fasta", "NC_012532.1.fasta", "NC_045512.2.fasta", "NC_038312.1.fasta", "NC_002728.1.fasta", "NC_006273.2.fasta", "NC_001803.1.fasta", "NC_009333.1.fasta", "NC_001348.1.fasta", "NC_001798.2.fasta", "NC_001538.1.fasta", "NC_001355.1.fasta", "NC_001436.1.fasta", "NC_005219.1.fasta", "NC_001430.1.fasta", "NC_001906.3.fasta", "NC_038311.1.fasta", "NC_010415.1.fasta", "NC_001731.1.fasta", "JX276378.1.fasta", "NC_006307.0.fasta", "NC_001806.2.fasta", "NC_001796.2.fasta", "NC_001611.1.fasta", "NC_003443.1.fasta", "NC_001664.4.fasta", "NC_002549.1.fasta", "NC_004102.1.fasta", "NC_002204.0.fasta", "NC_007605.1.fasta", "NC_004162.2.fasta"];
var virusHostMat = [[0,0.000884801,0.000918632,0.00105935,0.000910986,0.000458362,0.0015677,0.00157808,0.00119264,0.000797509,0.000555235,0.00120107,0.000825763,0.0016784,0.00119908,0.000641724,0.00103277,0.00333569,0.00277843,0.00223994,0.00139483,0.00101938,0.000756764,0.00110001,0.00123964,0.000743896,0.0063625,0.000849508,0.0016852,0.00318606,0.00138494,0.0016338,0.000788023,0.00228366,0.000663528,0.00360533,0.00113414,0.00157314,0.000612755],
[0.000884801,0,0.00107469,0.00118367,0.000963045,0.00108281,0.00160491,0.00161129,0.00118367,0.000948972,0.00104988,0.0012221,0.000805417,0.0016784,0.00118558,0.0010242,0.0010155,0.00330298,0.00271496,0.00211006,0.00136211,0.000910449,0.000930735,0.000757718,0.00110976,0.00104731,0.0063957,0.00111604,0.00155779,0.00315335,0.00117352,0.00156753,0.000796445,0.00222019,0.00075239,0.00354186,0.00095779,0.00160635,0.00100745],
[0.000918632,0.00107469,0,0.00104999,0.00112215,0.000892155,0.00159615,0.00150231,0.00104109,0.0013704,0.000843266,0.000911404,0.000933293,0.00162391,0.00112061,0.00111231,0.00100903,0.00307985,0.00208455,0.002297,0.00113898,0.000998746,0.000912949,0.0012354,0.0012967,0.00104874,0.00628672,0.00121387,0.00129508,0.00293021,0.00122749,0.00169085,0.000987352,0.00158978,0.000789659,0.00291145,0.00100999,0.00160635,0.00116295],
[0.00105935,0.00118367,0.00104999,0,0.00105797,0.0010245,0.00172768,0.00151471,0.000908506,0.000981386,0.00100846,0.00127965,0.00104161,0.00153353,0.00141797,0.00105858,0.00100282,0.00315914,0.00267284,0.00192307,0.00121827,0.00114961,0.00102323,0.00120571,0.00104996,0.00114761,0.00629912,0.00102373,0.00117743,0.0030095,0.00145565,0.00146656,0.00106307,0.00217808,0.00102707,0.00349974,0.000973612,0.00160635,0.00105605],
[0.000910986,0.000963045,0.00112215,0.00105797,0,0.000874082,0.00163159,0.00161129,0.00111197,0.000770649,0.000986796,0.00100411,0.000892509,0.0016784,0.00144101,0.000933827,0.00106053,0.00331553,0.00242256,0.00233244,0.00137466,0.000988801,0.000930593,0.000956618,0.00133214,0.000867171,0.0063957,0.000811469,0.00133168,0.00316589,0.00143354,0.00172629,0.000821543,0.00192779,0.000734595,0.00324945,0.00122187,0.00160635,0.00100745],
[0.000458362,0.00108281,0.000892155,0.0010245,0.000874082,0,0.00162528,0.00147682,0.0011582,0.000859634,0.000482504,0.000926377,0.000776291,0.0016784,0.00131562,0.000623351,0.000917718,0.00330187,0.00259065,0.00223789,0.0013862,0.00104049,0.000782728,0.000945027,0.00123759,0.000750872,0.00626123,0.00101472,0.00147877,0.00315224,0.00122668,0.00163174,0.000747406,0.00209589,0.000637776,0.00341755,0.000927712,0.00160635,0.000696747],
[0.0015677,0.00160491,0.00159615,0.00172768,0.00163159,0.00162528,0,0.00178194,0.0020287,0.00198236,0.00149743,0.00173073,0.001358,0.00179353,0.000897141,0.0017034,0.00140034,0.00334716,0.00172257,0.00141432,0.00173465,0.00145861,0.00173228,0.00163186,0.00166985,0.00181133,0.00637516,0.00188062,0.00168684,0.00319753,0.00116347,0.000372512,0.00151722,0.0012448,0.00137668,0.00203763,0.00163208,0.00185119,0.00183625],
[0.00157808,0.00161129,0.00150231,0.00151471,0.00161129,0.00147682,0.00178194,0,0.00161129,0.00161129,0.00161129,0.00161129,0.00161129,0.000735287,0.00161129,0.00111841,0.00149918,0.00299115,0.00189964,0.00235042,0.00161129,0.00161129,0.00161129,0.00155643,0.00161129,0.00147494,0.00478441,0.00161129,0.00161129,0.00284151,0.00161129,0.00174427,0.00161129,0.00142933,0.00161129,0.00272654,0.00161129,0.00137849,0.0014421],
[0.00119264,0.00118367,0.00104109,0.000908506,0.00111197,0.0011582,0.0020287,0.00161129,0,0.00123106,0.0012256,0.00125905,0.00114941,0.00140256,0.00134993,0.00117724,0.00116419,0.00319492,0.00269612,0.00240598,0.00125405,0.00125905,0.0010338,0.00125905,0.00140568,0.00128008,0.0063957,0.00128119,0.00147793,0.00304528,0.00161739,0.0018618,0.00119511,0.00220135,0.00120629,0.00352301,0.00126336,0.00160635,0.00112035],
[0.000797509,0.000948972,0.0013704,0.000981386,0.000770649,0.000859634,0.00198236,0.00161129,0.00123106,0,0.0011372,0.00124948,0.000948923,0.00163206,0.00151455,0.000697779,0.000984953,0.00302789,0.00259379,0.00240598,0.00108703,0.00133831,0.00122166,0.00125984,0.00154625,0.000954459,0.0063957,0.000884312,0.00169633,0.00287826,0.0015247,0.00181546,0.000947857,0.00209902,0.000903324,0.00342068,0.0010165,0.00142098,0.000765771],
[0.000555235,0.00104988,0.000843266,0.00100846,0.000986796,0.000482504,0.00149743,0.00161129,0.0012256,0.0011372,0,0.000838029,0.00080748,0.0016784,0.00123025,0.000945951,0.000719844,0.0033523,0.00240883,0.0021384,0.00144543,0.000973938,0.000797849,0.00103095,0.0011381,0.000917231,0.0063957,0.00094817,0.0012978,0.00320266,0.00138326,0.00153225,0.000755072,0.00191406,0.000722193,0.00323573,0.000845267,0.0015729,0.0010526],
[0.00120107,0.0012221,0.000911404,0.00127965,0.00100411,0.000926377,0.00173073,0.00161129,0.00125905,0.00124948,0.000838029,0,0.00111776,0.0016784,0.00124759,0.00103175,0.00119581,0.00328288,0.00294146,0.00185065,0.00139022,0.00103831,0.00119088,0.00117225,0.00119656,0.000904882,0.0063957,0.00119262,0.00153358,0.00313325,0.00133973,0.00147176,0.00112253,0.00244669,0.000874583,0.00376836,0.00106344,0.00160635,0.00124948],
[0.000825763,0.000805417,0.000933293,0.00104161,0.000892509,0.000776291,0.001358,0.00161129,0.00114941,0.000948923,0.00080748,0.00111776,0,0.0016784,0.000889619,0.00097367,0.000991098,0.00327007,0.00224338,0.0019674,0.0013292,0.00104161,0.000853589,0.000547945,0.000967106,0.000796318,0.0063957,0.000973987,0.00128909,0.00312043,0.00085534,0.00136126,0.000644261,0.00174861,0.000883332,0.00307027,0.000781358,0.00149671,0.000982062],
[0.0016784,0.0016784,0.00162391,0.00153353,0.0016784,0.0016784,0.00179353,0.000735287,0.00140256,0.00163206,0.0016784,0.0016784,0.0016784,0,0.0016784,0.00105505,0.00143416,0.00304463,0.00199238,0.0021853,0.00126673,0.0016784,0.0016784,0.0016784,0.0016784,0.0016784,0.0053772,0.00161078,0.0016784,0.00289499,0.00164605,0.00165415,0.0016784,0.00149761,0.0016784,0.00281928,0.0016423,0.00131905,0.00150921],
[0.00119908,0.00118558,0.00112061,0.00141797,0.00144101,0.00131562,0.000897141,0.00161129,0.00134993,0.00151455,0.00123025,0.00124759,0.000889619,0.0016784,0,0.0013116,0.00100381,0.00328645,0.00174825,0.00148408,0.00136443,0.00117854,0.00144668,0.00116347,0.00117643,0.00151455,0.0063957,0.00144693,0.00109657,0.00313681,0.000761339,0.000877929,0.0009401,0.00119911,0.00101354,0.00252077,0.00138285,0.00160635,0.00134536],
[0.000641724,0.0010242,0.00111231,0.00105858,0.000933827,0.000623351,0.0017034,0.00111841,0.00117724,0.000697779,0.000945951,0.00103175,0.00097367,0.00105505,0.0013116,0,0.000706068,0.00275069,0.00228968,0.00216678,0.000978184,0.00108023,0.000909989,0.00131914,0.00123457,0.000985027,0.00590282,0.000853638,0.00173988,0.00260106,0.00137457,0.00159809,0.00100948,0.00179491,0.000871366,0.00311657,0.00130931,0.00106273,0.000608854],
[0.00103277,0.0010155,0.00100903,0.00100282,0.00106053,0.000917718,0.00140034,0.00149918,0.00116419,0.000984953,0.000719844,0.00119581,0.000991098,0.00143416,0.00100381,0.000706068,0,0.00277554,0.00174565,0.00158118,0.00129282,0.000871498,0.00119735,0.00109458,0.00112466,0.00119705,0.00628359,0.00126522,0.00164979,0.002518,0.00126905,0.00121227,0.000854535,0.00125089,0.00078457,0.00257255,0.00130789,0.00123259,0.000855802],
[0.00333569,0.00330298,0.00307985,0.00315914,0.00331553,0.00330187,0.00334716,0.00299115,0.00319492,0.00302789,0.0033523,0.00328288,0.00327007,0.00304463,0.00328645,0.00275069,0.00277554,0,0.0033523,0.00316235,0.0025915,0.00321383,0.00328443,0.00327001,0.0033523,0.0033523,0.00385481,0.0033523,0.0033523,0.0009239,0.0033523,0.0033496,0.00312853,0.003117,0.00329954,0.00347895,0.00328011,0.00245317,0.0033523],
[0.00277843,0.00271496,0.00208455,0.00267284,0.00242256,0.00259065,0.00172257,0.00189964,0.00269612,0.00259379,0.00240883,0.00294146,0.00224338,0.00199238,0.00174825,0.00228968,0.00174565,0.0033523,0,0.00163759,0.00242278,0.00190315,0.00294301,0.00262687,0.00287031,0.0029427,0.0063957,0.00301088,0.00223085,0.00320266,0.00233157,0.00172131,0.00253137,0.00164158,0.00227225,0.001554,0.00257773,0.00285082,0.00220722],
[0.00223994,0.00211006,0.002297,0.00192307,0.00233244,0.00223789,0.00141432,0.00235042,0.00240598,0.00240598,0.0021384,0.00185065,0.0019674,0.0021853,0.00148408,0.00216678,0.00158118,0.00316235,0.00163759,0,0.00217074,0.00157518,0.00227024,0.0018574,0.00125237,0.00240598,0.00626907,0.00213549,0.00185996,0.00301272,0.00125802,0.00144823,0.00151461,0.00185381,0.00203666,0.00244484,0.0021894,0.00236524,0.00215219],
[0.00139483,0.00136211,0.00113898,0.00121827,0.00137466,0.0013862,0.00173465,0.00161129,0.00125405,0.00108703,0.00144543,0.00139022,0.0013292,0.00126673,0.00136443,0.000978184,0.00129282,0.0025915,0.00242278,0.00217074,0,0.00152905,0.00134356,0.00139887,0.00152905,0.00141143,0.0063957,0.00141143,0.00165603,0.00229108,0.00155858,0.00156775,0.00130528,0.00192801,0.00135867,0.00324968,0.00133924,0.00125349,0.00141143],
[0.00101938,0.000910449,0.000998746,0.00114961,0.000988801,0.00104049,0.00145861,0.00161129,0.00125905,0.00133831,0.000973938,0.00103831,0.00104161,0.0016784,0.00117854,0.00108023,0.000871498,0.00321383,0.00190315,0.00157518,0.00152905,0,0.00104258,0.00112194,0.00119693,0.00103955,0.0063957,0.00118179,0.00165169,0.0030642,0.00134046,0.00156003,0.000979857,0.00140838,0.000896689,0.00273005,0.00123909,0.00160635,0.00113087],
[0.000756764,0.000930735,0.000912949,0.00102323,0.000930593,0.000782728,0.00173228,0.00161129,0.0010338,0.00122166,0.000797849,0.00119088,0.000853589,0.0016784,0.00144668,0.000909989,0.00119735,0.00328443,0.00294301,0.00227024,0.00134356,0.00104258,0,0.000908338,0.00126994,0.000683283,0.0063957,0.000747068,0.00138838,0.00313479,0.00121017,0.00166409,0.000890184,0.00244824,0.000833396,0.00376991,0.00110881,0.00160635,0.00122166],
[0.00110001,0.000757718,0.0012354,0.00120571,0.000956618,0.000945027,0.00163186,0.00155643,0.00125905,0.00125984,0.00103095,0.00117225,0.000547945,0.0016784,0.00116347,0.00131914,0.00109458,0.00327001,0.00262687,0.0018574,0.00139887,0.00112194,0.000908338,0,0.000944582,0.000905151,0.00634085,0.000904621,0.00142592,0.00312038,0.00088248,0.00143124,0.00068473,0.00213211,0.000664587,0.00345377,0.000994879,0.00160635,0.00110279],
[0.00123964,0.00110976,0.0012967,0.00104996,0.00133214,0.00123759,0.00166985,0.00161129,0.00140568,0.00154625,0.0011381,0.00119656,0.000967106,0.0016784,0.00117643,0.00123457,0.00112466,0.0033523,0.00287031,0.00125237,0.00152905,0.00119693,0.00126994,0.000944582,0,0.00140568,0.0063957,0.00113519,0.00108311,0.00320266,0.00110423,0.00146796,0.00116264,0.00237554,0.00103636,0.00369721,0.0011891,0.00160635,0.00154625],
[0.000743896,0.00104731,0.00104874,0.00114761,0.000867171,0.000750872,0.00181133,0.00147494,0.00128008,0.000954459,0.000917231,0.000904882,0.000796318,0.0016784,0.00151455,0.000985027,0.00119705,0.0033523,0.0029427,0.00240598,0.00141143,0.00103955,0.000683283,0.000905151,0.00140568,0,0.00625935,0.000810362,0.00186256,0.00320266,0.00129391,0.00179983,0.000927051,0.00244793,0.000813316,0.0037696,0.00120723,0.00147,0.000989795],
[0.0063625,0.0063957,0.00628672,0.00629912,0.0063957,0.00626123,0.00637516,0.00478441,0.0063957,0.0063957,0.0063957,0.0063957,0.0063957,0.0053772,0.0063957,0.00590282,0.00628359,0.00385481,0.0063957,0.00626907,0.0063957,0.0063957,0.0063957,0.00634085,0.0063957,0.00625935,0,0.0063957,0.0063957,0.0045825,0.0063957,0.00638493,0.0063957,0.00621374,0.0063957,0.00598081,0.0063957,0.0061629,0.00622651],
[0.000849508,0.00111604,0.00121387,0.00102373,0.000811469,0.00101472,0.00188062,0.00161129,0.00128119,0.000884312,0.00094817,0.00119262,0.000973987,0.00161078,0.00144693,0.000853638,0.00126522,0.0033523,0.00301088,0.00213549,0.00141143,0.00118179,0.000747068,0.000904621,0.00113519,0.000810362,0.0063957,0,0.00172897,0.00320266,0.00154977,0.00165893,0.000954089,0.00251611,0.000870921,0.00383778,0.00114639,0.00147111,0.000955066],
[0.0016852,0.00155779,0.00129508,0.00117743,0.00133168,0.00147877,0.00168684,0.00161129,0.00147793,0.00169633,0.0012978,0.00153358,0.00128909,0.0016784,0.00109657,0.00173988,0.00164979,0.0033523,0.00223085,0.00185996,0.00165603,0.00165169,0.00138838,0.00142592,0.00108311,0.00186256,0.0063957,0.00172897,0,0.00320266,0.00133455,0.00143919,0.00124359,0.00173608,0.00109104,0.00305774,0.00109249,0.00185756,0.00155951],
[0.00318606,0.00315335,0.00293021,0.0030095,0.00316589,0.00315224,0.00319753,0.00284151,0.00304528,0.00287826,0.00320266,0.00313325,0.00312043,0.00289499,0.00313681,0.00260106,0.002518,0.0009239,0.00320266,0.00301272,0.00229108,0.0030642,0.00313479,0.00312038,0.00320266,0.00320266,0.0045825,0.00320266,0.00320266,0,0.00320266,0.00319997,0.00297889,0.00296737,0.00314991,0.00352572,0.00313047,0.0018838,0.00320266],
[0.00138494,0.00117352,0.00122749,0.00145565,0.00143354,0.00122668,0.00116347,0.00161129,0.00161739,0.0015247,0.00138326,0.00133973,0.00085534,0.00164605,0.000761339,0.00137457,0.00126905,0.0033523,0.00233157,0.00125802,0.00155858,0.00134046,0.00121017,0.00088248,0.00110423,0.00129391,0.0063957,0.00154977,0.00133455,0.00320266,0,0.000961575,0.000978045,0.00183681,0.00127445,0.00315847,0.00129391,0.00154166,0.00153279],
[0.0016338,0.00156753,0.00169085,0.00146656,0.00172629,0.00163174,0.000372512,0.00174427,0.0018618,0.00181546,0.00153225,0.00147176,0.00136126,0.00165415,0.000877929,0.00159809,0.00121227,0.0033496,0.00172131,0.00144823,0.00156775,0.00156003,0.00166409,0.00143124,0.00146796,0.00179983,0.00638493,0.00165893,0.00143919,0.00319997,0.000961575,0,0.00135032,0.00135696,0.00143052,0.0022966,0.00158326,0.00175909,0.0015886],
[0.000788023,0.000796445,0.000987352,0.00106307,0.000821543,0.000747406,0.00151722,0.00161129,0.00119511,0.000947857,0.000755072,0.00112253,0.000644261,0.0016784,0.0009401,0.00100948,0.000854535,0.00312853,0.00253137,0.00151461,0.00130528,0.000979857,0.000890184,0.00068473,0.00116264,0.000927051,0.0063957,0.000954089,0.00124359,0.00297889,0.000978045,0.00135032,0,0.0020366,0.000646491,0.00335827,0.00100868,0.00160635,0.00101262],
[0.00228366,0.00222019,0.00158978,0.00217808,0.00192779,0.00209589,0.0012448,0.00142933,0.00220135,0.00209902,0.00191406,0.00244669,0.00174861,0.00149761,0.00119911,0.00179491,0.00125089,0.003117,0.00164158,0.00185381,0.00192801,0.00140838,0.00244824,0.00213211,0.00237554,0.00244793,0.00621374,0.00251611,0.00173608,0.00296737,0.00183681,0.00135696,0.0020366,0,0.00177748,0.0013411,0.00208296,0.00235606,0.00171246],
[0.000663528,0.00075239,0.000789659,0.00102707,0.000734595,0.000637776,0.00137668,0.00161129,0.00120629,0.000903324,0.000722193,0.000874583,0.000883332,0.0016784,0.00101354,0.000871366,0.00078457,0.00329954,0.00227225,0.00203666,0.00135867,0.000896689,0.000833396,0.000664587,0.00103636,0.000813316,0.0063957,0.000870921,0.00109104,0.00314991,0.00127445,0.00143052,0.000646491,0.00177748,0,0.00309915,0.000973179,0.00150083,0.000896908],
[0.00360533,0.00354186,0.00291145,0.00349974,0.00324945,0.00341755,0.00203763,0.00272654,0.00352301,0.00342068,0.00323573,0.00376836,0.00307027,0.00281928,0.00252077,0.00311657,0.00257255,0.00347895,0.001554,0.00244484,0.00324968,0.00273005,0.00376991,0.00345377,0.00369721,0.0037696,0.00598081,0.00383778,0.00305774,0.00352572,0.00315847,0.0022966,0.00335827,0.0013411,0.00309915,0,0.00340463,0.00367772,0.00303412],
[0.00113414,0.00095779,0.00100999,0.000973612,0.00122187,0.000927712,0.00163208,0.00161129,0.00126336,0.0010165,0.000845267,0.00106344,0.000781358,0.0016423,0.00138285,0.00130931,0.00130789,0.00328011,0.00257773,0.0021894,0.00133924,0.00123909,0.00110881,0.000994879,0.0011891,0.00120723,0.0063957,0.00114639,0.00109249,0.00313047,0.00129391,0.00158326,0.00100868,0.00208296,0.000973179,0.00340463,0,0.00160635,0.00121994],
[0.00157314,0.00160635,0.00160635,0.00160635,0.00160635,0.00160635,0.00185119,0.00137849,0.00160635,0.00142098,0.0015729,0.00160635,0.00149671,0.00131905,0.00160635,0.00106273,0.00123259,0.00245317,0.00285082,0.00236524,0.00125349,0.00160635,0.00160635,0.00160635,0.00160635,0.00147,0.0061629,0.00147111,0.00185756,0.0018838,0.00154166,0.00175909,0.00160635,0.00235606,0.00150083,0.00367772,0.00160635,0,0.00152176],
[0.000612755,0.00100745,0.00116295,0.00105605,0.00100745,0.000696747,0.00183625,0.0014421,0.00112035,0.000765771,0.0010526,0.00124948,0.000982062,0.00150921,0.00134536,0.000608854,0.000855802,0.0033523,0.00220722,0.00215219,0.00141143,0.00113087,0.00122166,0.00110279,0.00154625,0.000989795,0.00622651,0.000955066,0.00155951,0.00320266,0.00153279,0.0015886,0.00101262,0.00171246,0.000896908,0.00303412,0.00121994,0.00152176,0]];
var superkingdomArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var phylumArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var classArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var orderArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var familyArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var genusArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var speciesArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var organismArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];

   for(var hostIdx=0; hostIdx<hostNameArr.length; hostIdx++) hostNameIdxMap[hostNameArr[hostIdx]] = hostIdx;
   for(var virusIdx=0; virusIdx<virusNameArr.length; virusIdx++) virusNameIdxMap[virusNameArr[virusIdx]] = virusIdx;
   console.log("phageToHost finish loading!");
   
   topHostNum = Math.min(25, hostNameArr.length);
   
   $(function() { $( "#topSlider" ).slider({ value:25, min: 1, max: 100, step: 1, slide: function( event, ui ) { $( "#topAmount" ).val( ui.value ); topHostNum = Math.min(ui.value, hostNameArr.length);  } }); }); 
   $(function() { $( "#cutoffSlider" ).slider({ value:1, min: 0, max: 1, step: 0.01, slide: function( event, ui ) { $( "#cutoffAmount" ).val( ui.value ); cutoff = ui.value; } }); });
   
   
   $("#listbox").jqxListBox({width: 290, height: 300, source: virusNameArr, checkboxes: true, filterable: true});
		$("#listbox").on('checkChange', function (event) {
			var items = $("#listbox").jqxListBox('getCheckedItems');
			checkedVirusIdxArr = []; checkedVirusArr = [];
			$.each(items, function (index) { checkedVirusIdxArr.push(this.index); checkedVirusArr.push(this.label); });
			
			if(checkedVirusIdxArr.length > 0) $("#okBtn").prop('disabled', false);
			else $("#okBtn").prop('disabled', true);
   });
   
   var host2organism = [], host2superkingdom = [], host2phylum = [], host2class = [], 
		host2order = [], host2family = [], host2genus = [], host2species = [];
   
   for(var t=0; t<hostNameArr.length; t++){
   		host2organism[hostNameArr[t]] = organismArr[t];
   		host2superkingdom[hostNameArr[t]] = superkingdomArr[t];
   		host2phylum[hostNameArr[t]] = phylumArr[t];
   		host2class[hostNameArr[t]] = classArr[t];
   		host2order[hostNameArr[t]] = orderArr[t];
   		host2family[hostNameArr[t]] = familyArr[t];
   		host2genus[hostNameArr[t]] = genusArr[t];
   		host2species[hostNameArr[t]] = speciesArr[t];
	}
	console.log("hostTaxonomy finish loading!");
	
	var minDist = 1, maxDist = 0, gap=0;
	for(var rowIdx=0; rowIdx<virusHostMat.length; rowIdx++) 
	{
		for(var colIdx=0; colIdx<virusHostMat[0].length; colIdx++)
		{
			if(virusHostMat[rowIdx][colIdx]<minDist) minDist = virusHostMat[rowIdx][colIdx];
			if(virusHostMat[rowIdx][colIdx]>maxDist) maxDist = virusHostMat[rowIdx][colIdx];
		}
	}
	minDist = Math.max(0,minDist-0.1); maxDist = Math.min(1,maxDist+0.1); gap = maxDist-minDist;
	var colorScale = d3.scale.quantile().domain([minDist,maxDist]).range(colors);

	function updateData() {
		topHostNum = Math.min(topHostNum, hostNameArr.length);

		var combinedArr = new Array(virusHostMat[checkedVirusIdxArr[0]].length).fill(0);
		for(var rowIdx=0; rowIdx<checkedVirusIdxArr.length; rowIdx++) {
			for(var colIdx=0; colIdx<virusHostMat[checkedVirusIdxArr[rowIdx]].length; colIdx++) {
				combinedArr[colIdx] += virusHostMat[checkedVirusIdxArr[rowIdx]][colIdx];
			}
		}
		var tmpArr = combinedArr.slice(); 
		var thres = tmpArr.sort().slice(topHostNum-1,topHostNum);

		indiceArr = [];
		for(var colIdx=0; colIdx<combinedArr.length; colIdx++) {
			if(indiceArr.length >= topHostNum) break;
			if(combinedArr[colIdx] <= thres) { indiceArr.push({"idx":colIdx, "dist":combinedArr[colIdx] }); }
		}
		
		hostArr = []; edgeData =[];
		for(var colIdx=0; colIdx<indiceArr.length; colIdx++) {
			var realColIdx = indiceArr[colIdx].idx;
			hostArr.push(hostNameArr[realColIdx]);
			
			for(var rowIdx=0; rowIdx<checkedVirusIdxArr.length; rowIdx++) { edgeData.push({"row":rowIdx, "col":hostArr.length-1, 
				"value":virusHostMat[checkedVirusIdxArr[rowIdx]][realColIdx]<=cutoff?virusHostMat[checkedVirusIdxArr[rowIdx]][realColIdx]:1}); }
		}
		
		pathArr = [];
		for(var colIdx=0; colIdx<hostArr.length; colIdx++) { pathArr.push([host2superkingdom[hostArr[colIdx]],host2phylum[hostArr[colIdx]],host2class[hostArr[colIdx]],host2order[hostArr[colIdx]],host2family[hostArr[colIdx]],host2genus[hostArr[colIdx]],host2species[hostArr[colIdx]]]); }
		//rootNode = 	convertToHierarchy(pathArr);
		//consensusArr = getConsensusTaxonomy(rootNode); 
		
		$("#consensusSuperkingdom").text("Superkingdom: "+getConsensusItem(pathArr,0));
		$("#consensusPhylum").text("Phylum: "+getConsensusItem(pathArr,1));
		$("#consensusClass").text("Class: "+getConsensusItem(pathArr,2));
		$("#consensusOrder").text("Order: "+getConsensusItem(pathArr,3));
		$("#consensusFamily").text("Family: "+getConsensusItem(pathArr,4));
		$("#consensusGenus").text("Genus: "+getConsensusItem(pathArr,5));
		$("#consensusSpecies").text("Species: "+getConsensusItem(pathArr,6));
		
		var cellSize = 25, legendElementWidth = cellSize*2, 
			width = Math.max(hostArr.length*cellSize, 1000 ), height = Math.max(checkedVirusIdxArr.length*cellSize, 700 );
		
		console.log();
		
		d3.selectAll(".canvasSvg").remove(); 
		var svg = d3.select("#heatCanvas").style("float", "left").attr("width", width).attr("height", height)
			.append("g").attr('class', "canvasSvg").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
			
		var rowLabels = svg.append("g").selectAll(".rowLabelg").data(checkedVirusArr).enter().append("text")
			.text(function (d) { return d; }).attr("x", 0).attr("y", function (d, i) { return i * cellSize; })
      		.style("text-anchor", "end").attr("transform", "translate(-6," + cellSize / 1.5 + ")")
      		.attr("class", function (d,i) { return "rowLabel mono r"+i;} ) ;
      		
      	var colLabels = svg.append("g").selectAll(".colLabelg").data(hostArr).enter().append("text")
      		.text(function (d) { return d; }).attr("x", 0).attr("y", function (d, i) { return i * cellSize; })
      		.style("text-anchor", "left").attr("transform", "translate("+cellSize/2 + ",-6) rotate (-90)")
      		.attr("class",  function (d,i) { return "colLabel mono c"+i;} );
      	
      	var heatMap = svg.append("g").attr("class","g3").selectAll(".cellg").data(edgeData).enter().append("rect")
			.attr("x", function(d) { return d.col * cellSize; }).attr("y", function(d) { return d.row * cellSize; })
        	.attr("class", function(d){return "cell cell-border cr"+(d.row)+" cc"+(d.col);})
        	.attr("width", cellSize).attr("height", cellSize).style("fill", function(d) { return colorScale(d.value); })
			.on("mouseover", function(d){
				d3.selectAll(".cell").filter(function(el) {return d.row == el.row || d.col == el.col; }).classed("cell-hover",true);
				d3.selectAll(".rowLabel").classed("text-highlight",function(r,ri){ return ri==d.row;});
				d3.selectAll(".colLabel").classed("text-highlight",function(c,ci){ return ci==d.col;});
				
				d3.select("#tooltip1").style("left", (d3.event.pageX+10) + "px").style("top", (d3.event.pageY-10) + "px")
					.html("Host Information: "+
						"<br> Superkingdom: "+ host2superkingdom[hostArr[d.col]] +
						"<br> Phylum: "+ host2phylum[hostArr[d.col]] +
						"<br> Class: "+ host2class[hostArr[d.col]] +
						"<br> Order: "+ host2order[hostArr[d.col]] +
						"<br> Family: "+ host2family[hostArr[d.col]] +
						"<br> Genus: "+ host2genus[hostArr[d.col]] +
						"<br> Species: "+ host2species[hostArr[d.col]] +
						"<br> Organism: "+ host2organism[hostArr[d.col]] +
						"<br> distance:"+d.value);  
                d3.select("#tooltip1").classed("hidden", false);
			})
			.on("mouseout", function(d){
				d3.selectAll(".cell").filter(function(el) {return d.row == el.row || d.col == el.col; }).classed("cell-hover",false);
				d3.selectAll(".rowLabel").classed("text-highlight",false);
				d3.selectAll(".colLabel").classed("text-highlight",false);
				d3.select("#tooltip1").classed("hidden", true);
			});
      		
      	var legend = svg.selectAll(".legend").data([minDist,minDist+0.1*gap,minDist+0.2*gap,minDist+0.3*gap,minDist+0.4*gap,minDist+0.5*gap,minDist+0.6*gap,minDist+0.7*gap,minDist+0.8*gap,minDist+0.9*gap,maxDist]).enter().append("g").attr("class", "legend");
		legend.append("rect").attr("x", function(d, i) { return legendElementWidth * i-margin.left; }).attr("y", (cellSize*2) - margin.top)
    		.attr("width", legendElementWidth).attr("height", cellSize)
    		.style("fill", function(d, i) { return colors[i]; });
    
    	legend.append("text").text(function(d) { return d3.format(".2f")(d); }).style("text-anchor", "left")
    		.attr("x", function(d, i) { return legendElementWidth * i-margin.left; }).attr("y", (cellSize*4)- margin.top);
	}
	
	function getConsensusItem(pathArr, idx)
	{
		var node = {id:"root", cnt:0, children:{}};
		for (var i = 0; i < pathArr.length; i++) 
		{
			var path = pathArr[i];
			node.cnt ++;
			item = path[idx];
			if (!node.children[item]) node.children[item] = {id:item, cnt:0, children:{}};
			node.children[item].cnt ++;
		}
		
		var arr = Object.keys( node.children ).map(function ( key ) { return node.children[key].cnt; });
		var ratio = 100;
		if(math.sum(arr) > 0) ratio = Math.max.apply(Math,arr)*100/math.sum(arr);
		maxItem = Object.keys(node.children)[arr.indexOf(Math.max.apply(Math,arr))];
		return node.children[maxItem].id+" ("+String(Math.round(ratio * 100) / 100)+"%)";
	}
	
	function convertToHierarchy(pathArr) {
		var rootNode = {id:"root", cnt:0, children:{}};
		for (var i = 0; i < pathArr.length; i++) {
			var path = pathArr[i];
			buildNodeRecursive(rootNode, path, 0);
		}
		return rootNode;
	}
	
	function buildNodeRecursive(node, path, idx) {
		if (idx < path.length) {
			node.cnt ++;
			item = path[idx];			
			if (!node.children[item]) node.children[item] = {id:item, cnt:0, children:{}};
			buildNodeRecursive(node.children[item], path, idx + 1);
		}
	}
	
	function getConsensusTaxonomy(currNode) {
		if(currNode.children && Object.keys(currNode.children).length > 0) {
			var arr = Object.keys( currNode.children ).map(function ( key ) { return currNode.children[key].cnt; });
			//console.log(arr + " : " +arr.length);
			//console.log(arr + " : " +Math.max.apply(Math,arr) +" : " + arr.indexOf(Math.max.apply(Math,arr)));
			//console.log(Math.max.apply(Math,arr) + " / " +math.sum(arr));
			
			var ratio = 100;
			if(math.sum(arr) > 0) ratio = Math.max.apply(Math,arr)*100/math.sum(arr);
			
			maxItem = Object.keys(currNode.children)[arr.indexOf(Math.max.apply(Math,arr))];
			
			returnArr = [currNode.children[maxItem].id+" ("+String(Math.round(ratio * 100) / 100)+"%)"];
			returnArr = returnArr.concat(getConsensusTaxonomy(currNode.children[maxItem]));
			return returnArr;
		}
		return [currNode.id+" (100%)"];
	}
	

</script>

</body>
</html>